<?php
include_once("config.php");
if (isset($_SESSION['adminName'])){
	$isAdmin=true;
}else{
	$isAdmin=false;
}
if (isset($_POST['dishname']) && isset($_POST['restuarantaddress']) && isset($_POST['dishinformation']) && isset($_POST['dishprice'])){
	$isInputValid=true;
}else{
	$isInputValid=false;
}
if ($isInputValid){
	$dishname=mysql_real_escape_string(stripcslashes($_POST['dishname']));
	$restuarantaddress=mysql_real_escape_string(stripcslashes($_POST['restuarantaddress']));
	$dishprice=intval(mysql_real_escape_string(stripcslashes($_POST['dishprice'])));
	$dishinformation=mysql_real_escape_string(stripcslashes($_POST['dishinformation']));
  
  if (!empty($restuarantaddress) && !empty($dishprice) && !empty($dishname)){
	  $queryStr="INSERT INTO dish VALUES('$restuarantaddress','$dishname','$dishinformation','$dishprice')";
	  mysql_query($queryStr) or die("Error: ".mysql_error()."<br/>go back <a href='viewdish.php'>here</a>");
	  $isSuccessful=true;
  }else{
  	$isSuccessful=false;
  }
}else{
	$isSuccessful=false;
}
if ($isAdmin && $isSuccessful){
  header("location: viewdish.php");
}else if(!$isAdmin){
  header("location: adminIndex.php");
}else if(!$isInputValid){
	echo "Input is not valid!<br/> go back <a href='viewdish.php'>here</a>";
}else{
	echo "Input format does not fulfill requirements. <br/> go back <a href='viewdish.php'>here</a>";
}
?>
